﻿using AdminStyem.Application.Command.ProcessingCommand;
using AdminStyem.Application.DTO;
using AdminStyem.Domain.Entity;
using AdminStyem.Repositories;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminStyem.Application.CommandHandler.ProcessingCommandHandler
{
    public class ProcessingShowCommandHandler : IRequestHandler<ProcessingShowCommand, APIResult<List<ProcessingDTO>>>
    {
        IBaseRespository<Processing> BaseProcessing;

        public ProcessingShowCommandHandler(IBaseRespository<Processing> baseProcessing)
        {
            BaseProcessing = baseProcessing;
        }

        public Task<APIResult<List<ProcessingDTO>>> Handle(ProcessingShowCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ProcessingDTO>> ret = new APIResult<List<ProcessingDTO>>();
            var processingList = BaseProcessing.GetAll().Result;
            var processingDTOList = processingList.Select(p => new ProcessingDTO
            {
                ProcessingId = p.ProcessingId,
                ProcessingTeam = p.ProcessingTeam,
                ProcessingHead = p.ProcessingHead,
                ProcessingPhoto = p.ProcessingPhoto,
                IsDeleted = p.IsDeleted
            }).ToList();

            ret.Code = ResultCode.查询成功;
            ret.Message = ResultCode.查询成功.ToString();
            ret.Data = processingDTOList;

            return Task.FromResult(ret);
        }
    }
}
